package dao;

import bean.ReturnBook;
import bean.ULog;
import utils.DbUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class ReturnBookDao {

    public int addRenturnBook(Connection connection, ReturnBook returnBook)throws Exception{
        DbUtil dbUtil=new DbUtil();
        connection=dbUtil.getCon();
        PreparedStatement ps=connection.prepareStatement("insert  into returnbook values (?,?,?,?,?,?,?)");
        ps.setInt(1,returnBook.getaId());
        ps.setInt(2,returnBook.getuId());
        ps.setInt(3,returnBook.getbId());
        ps.setString(4,returnBook.getBorrowTime());
        ps.setString(5,returnBook.getTime());
        ps.setString(6,returnBook.getDdl());
        ps.setString(7,returnBook.getBackTime());
        return ps.executeUpdate();
    }

    //已还书列表
    public ResultSet listReturnBook(Connection connection) throws Exception{
        DbUtil dbUtil=new DbUtil();
        ULog uLog=new ULog();
        ULogDao uLogDao=new ULogDao();
        uLog =uLogDao.readUser(connection);
        connection=dbUtil.getCon();
        PreparedStatement ps=connection.prepareStatement("select * from returnbook where user_id=?");
        ps.setInt(1,uLog.getuId());
        return ps.executeQuery();
    }
}
